<template>
  <!-- 公司荣誉统计 -->
  <base-breadcrumb :title="$route.meta.title">
    <!-- 搜索 -->
    <searchData
      :searchData="searchArr"
      @search="search"
    ></searchData>
    <!-- 表格 -->
    <a-card :bordered="false">
      <!-- <title-name :title="$route.meta.title"></title-name> -->

      <!-- 表格 -->
      <list-table
        ref="table"
        row-key="id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
      >
        <a-button
          slot="prefix"
          slot-scope="ref"
          v-btnPermission="'oa_001_add_01'"
          class="mb12"
          icon="plus"
          type="primary"
          @click="handleManage(2)"
        >新增</a-button>
        <template
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <a @click="handleManage(0, record)">查看</a>
            <template v-if="position === 'COADAZG' || record.isOperation === 1">
              <a
                v-btnPermission="'oa_001_edi_02'"
                @click="handleManage(1, record)"
              >编辑</a>
              <a
                v-btnPermission="'oa_001_del_03'"
                class="del_btn"
                @click="handleRemove(record.id)"
              >删除</a>
            </template>
          </MoreButton>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
// import { STable } from '@/components' // 表格
import { enterpriseHonor } from '@/api/office/office/enterpriseHonorAndImgCollect' // api
import TreeSelectOrganization from '@/components/TreeSelectOrganization'
import Selector from '@/components/Select/Selector'
import BasePage from '@/views/basePage' // 基础配置
import OrgTreeSelect from '@/components/OrgTreeSelect'

const searchArr = [
  // 搜索框
  {
    name: '荣誉名称',
    type: 'input',
    value: 'name'
  },
  {
    name: '获奖单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
  // {
  //   name: '获奖单位',
  //   type: TreeSelectOrganization,
  //   valueKey: 'awardWinningUnit',
  //   orgQuery: {
  //     containTags: ['CO', 'BC', 'PD'],
  //     resultWithCODept: true,
  //     resultWithBCDept: true,
  //     resultWithPDDept: true
  //   },
  //   containVirtual: true
  // },
  {
    name: '授奖单位',
    type: 'input',
    value: 'awardUnit'
  },
  {
    name: '荣誉级别',
    valueKey: 'levelId',
    type: Selector,
    selectType: '1',
    urlType: 'office'
  },
  {
    name: '获奖时间',
    type: 'dateRange',
    value: 'time',
    attr: {
      rangeFormat: ['startDate', 'endDate']
    }
  },
  {
    name: '形式',
    valueKey: 'formId',
    type: Selector,
    selectType: '2',
    urlType: 'office'
  }
]
const columns = [
  {
    title: '序号',
    width: 80,
    dataIndex: 'index',
    customRender() {
      return arguments[2] + 1
    }
  },
  {
    title: '荣誉名称',
    ellipsis: true,
    dataIndex: 'name'
  },
  {
    title: '荣誉级别',
    ellipsis: true,
    dataIndex: 'levelName'
  },
  {
    title: '获奖时间',
    ellipsis: true,
    dataIndex: 'awardTime'
  },
  {
    title: '获奖单位',
    ellipsis: true,
    dataIndex: 'awardWinningUnitName'
  },
  {
    title: '授奖单位',
    ellipsis: true,
    dataIndex: 'awardUnit'
  },
  {
    title: '形式',
    dataIndex: 'formName',
    ellipsis: true
  },
  {
    title: '是否移交归档',
    dataIndex: 'isTransfer',
    ellipsis: true,
    customRender(e) {
      return e ? '是' : '否'
    }
  },
  {
    title: '创建人',
    dataIndex: 'founder',
    ellipsis: true
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    ellipsis: true
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '180px',
    align: 'center',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),

  extends: new BasePage(),
  components: {
    // STable,
  },
  data() {
    this.columns = columns
    this.searchArr = searchArr
    return {
      queryParam: {}, // 查询参数
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, { query: this.queryParam })
        return enterpriseHonor.getList(requestParameters).then((res) => {
          return res
        })
      }, // 加载数据方法 必须为 Promise 对象
      removeApi: enterpriseHonor, // api
      editModel: 0,
      form: {},
      position: '' // 岗位
    }
  },
  mounted() {
    this.position = this.$currentPost()?.postCode
  },
  methods: {
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    // 操作栏
    handleManage(type, record) {
      this.editModel = type
      let query = {
        editModel: type
      }
      if (record && record.id) {
        query.id = record.id
      }
      this.$router.push({
        name: '/office/enterpriseHonor/enterpriseHonorEdit',
        query
      })
    }
  }
}
</script>
